package com.hjwoo.app.views;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.hjwoo.app.R;
import com.hjwoo.app.baseviews.BaseAppCompatActivity;
import com.hjwoo.app.utils.Utils;

/**
 * Created by Administrator on 2016/5/6 0006.
 * //评房成功
 */
public class HomeWebshowActivity extends BaseAppCompatActivity{


    private WebView  webView;

    @Override
    public void onResume()
    {
        super.onResume();
        webView.setFocusableInTouchMode(true);
        webView.requestFocus();
        webView.setOnKeyListener(new View.OnKeyListener()
        {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event)
            {

                if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK)
                {
                    //这里处理返回事件
                    if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack())
                    {
                        webView.goBack();
                        return true;
                    }
                }
                return false;
            }
        });
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_webshow);
        Utils.initTitle("佳信有约，国庆豪礼免费得", HomeWebshowActivity.this, true);

        init();
    }

    private void init() {

        webView = (WebView) findViewById(R.id.home_webview);
        webView.setOnKeyListener(new View.OnKeyListener()
        {
            @Override
            public boolean onKey(View view, int i, KeyEvent keyEvent)
            {
//                if(keyEvent.getAction() == KeyEvent.ACTION_DOWN){
                if (i == KeyEvent.KEYCODE_BACK && webView.canGoBack())
                {
                    webView.goBack();
                    return true;
                }
//                }
                return false;
            }
        });
        webView.loadUrl("http://mp.weixin.qq.com/s?__biz=MzI0NTM2ODg2Nw==&mid=2247484051&idx=1&sn=d1d006be251d141a61ef7057862f483e&chksm=e94ed3dfde395ac9f97dafbb4ea7bfca42077960a74799784d78f69e50b2e16951e99a152619&scene=0#rd");
//        webView.loadUrl("file:///android_asset/find.html");
        WebSettings wSettings = webView.getSettings();
        wSettings.setBuiltInZoomControls(true);
        wSettings.setUseWideViewPort(true);
        wSettings.setLoadWithOverviewMode(true);
        wSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        wSettings.setJavaScriptEnabled(true);
        wSettings.setDomStorageEnabled(true);
        wSettings.setAllowFileAccess(true);
        wSettings.setAppCacheEnabled(true);
        wSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        wSettings.setCacheMode(WebSettings.LOAD_DEFAULT);

        webView.setWebViewClient(new WebViewClient()
        {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
                view.loadUrl(url);
                return true;
            }
        });
    }


}
